package edu.mobbuzz.web.facade;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import edu.mobbuzz.daf.bean.Stream;
import edu.mobbuzz.daf.dao.IStreamDao;
import edu.mobbuzz.util.DBUtility;

public class TrafficFacade extends BaseFacade {
	private IStreamDao streamDao;

	public IStreamDao getStreamDao() {
		if(streamDao==null)
			streamDao = (IStreamDao)getFactory().getBean("streamDao");
		return streamDao;
	}
	
	public Stream getTrafficByPrimaryKey(String id){
		Stream stream = (Stream)getStreamDao().findByPrimaryKey(id);
		return stream;
	}
	
	public List<Stream> getTrafficList(String where, String order){
		List streamList = new ArrayList<Stream>();
		streamList = getStreamDao().queryForList(where, order);
		return streamList;
	}
	
	public void removeTraffic(Stream stream){
		getStreamDao().delete(stream);
	}
	
	public void addTraffic(String from, String to, String stream){
		Stream _stream = new Stream();
		_stream.setId(DBUtility.generateId());
		_stream.setSender(from);
		_stream.setRecepient(to);
		_stream.setStream(stream);
		_stream.setDate(new Date());
		try{
			getStreamDao().insert(_stream);
		}catch (Exception e) {
			e.printStackTrace();
		}		
	}
	
	public void updateTraffic(Stream stream){
		try{
			getStreamDao().update(stream);
		}catch (Exception e) {
			e.printStackTrace();
		}
		
	}
}
